package com.zmx.patients.view.util;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.zmx.patients.R;

public class TimeCount extends CountDownTimer {

    private TextView textView;

    /**
     *
     * @param textView 显示的控件
     * @param millisInFuture 总时长
     * @param countDownInterval 时间间隔
     */
    public TimeCount(TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.textView = textView;
    }

    /**
     * 计时过程显示
     * @param millisUntilFinished
     */
    @Override
    public void onTick(long millisUntilFinished) {
        String time = millisUntilFinished / 1000 + "s后重发";
        setButtonInfo(time, false);
    }

    /**
     * 计时完毕
     */
    @Override
    public void onFinish() {
        setButtonInfo("获取验证码", true);
    }

    /**
     * 验证按钮在点击前后相关设置
     *
     * @param content 要显示的内容
     * @param isClick 是否可点击
     */
    private void setButtonInfo(String content, boolean isClick) {

        textView.setText(content);
        if (isClick) {
            textView.setTextColor(Color.parseColor("#a0000000"));
            textView.setBackgroundResource(R.drawable.textview_true);
        } else {
            textView.setTextColor(Color.parseColor("#a0000000"));
            textView.setBackgroundResource(R.drawable.textview_false);
        }

        textView.setClickable(isClick);
    }
}